﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Security;

namespace Hired
{
    public partial class WebForm2 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void btnLogin_Click(object sender, EventArgs e)
        {
            if (txtUser.Text != "" && txtPassword.Text != "")
            {
                AdminStaffAccount loginAccount = new AdminStaffAccount();
                if (DBAdminStaffAccount.retrieveAdminStaffAccountByUsername(txtUser.Text) != null)
                {
                    loginAccount = DBAdminStaffAccount.retrieveAdminStaffAccountByUsername(txtUser.Text);
                }
                if (Encryption.verify(txtPassword.Text,loginAccount.Password))
                {
                    Session["username"] = loginAccount.Username;
                    FormsAuthentication.RedirectFromLoginPage(loginAccount.ASAccountID, true);
                    Response.Redirect("/Admin/home.aspx");
                }
                else
                {
                    lblErrorMsg.Text = "Wrong username or password!";
                }
            }
            else {
                lblErrorMsg.Text = "Please fill in all the fields.";
            }
        }
    }
}